#!/usr/bin/env python

import datetime
import os
import sys
 
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.mlab as mlab
import matplotlib.cbook as cbook
import numpy

def plot(data):
    hours = mdates.HourLocator()
    hform = mdates.DateFormatter('%H')
    mins = mdates.MinuteLocator()
    mform = mdates.DateFormatter('%M')
    secs = mdates.SecondLocator()
    secform = mdates.DateFormatter('%S')
    
    #locator = mdates.AutoDateLocator()
    #formatter = mdates.AutoDateFormatter(locator)
    
    fig = plt.figure()

    ax = fig.add_subplot(111)

    a = numpy.array(data)

    ax.plot(a[:,1], a[:,2])
    ax.xaxis.set_major_locator(mins)
    ax.xaxis.set_major_formatter(mform)
    ax.xaxis.set_minor_locator(secs)

    ax.format_xdata = mdates.DateFormatter('%H:%M:%S')

    import StringIO

    imgfs = StringIO.StringIO()

    fig.savefig(imgfs)

    import base64

    print base64.b64encode(imgfs.getvalue()),
